let db = require('../db.js');

//获取所有版本列表
exports.versionLists = async function () {
   let sql=`
   SELECT *,
   DATE_FORMAT(createdAt,'%Y-%m-%d %H:%i') AS createdAt 
   FROM  version  where isdelete ='n'
   ` 
   let  data  = await db.query(sql);
   return data[0];
}

//判断该版本号是否唯一
exports.validateNum =  async function(num){
    let  sql=`
    SELECT *FROM  version  where isdelete ='n' AND num =:num
    `
    let data = await db.query(sql,{num});
    return data[0];
}

//获取最大版本号
exports.getMaxNum  =   async function(){
    let sql=`
    SELECT MAX(num) AS maxNum FROM version where isdelete ='n'
    `
    let data = await db.query(sql);
    return data[0][0];
}

//新增版本
exports.addVersion = async  function(num,content,url){
let  sql=`
INSERT INTO version(num,content,url)
VALUES(:num,:content,:url)

`
let data =  await db.query(sql,{num,content,url});
return data[0];
}

//删除版本
exports.delVersion = async function(id){
    let sql=`
    UPDATE version SET  isdelete ='y'  where id=:id
    `
    let data  = await db.query(sql,{id});
    return data[0];
}